package com.bilibili.juc.me;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.ThreadDemoTest")
public class ThreadDemoTest {
     static int count = 10;
    public static void main(String[] args) {
        MyData myData = new MyData();
        new Thread(() -> {
            log.debug("start {}",myData.getCount());
            for (;count==10;){
                //log.debug("{}",myData.getCount());
    /*            try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }*/
                int i=10;
                int sum = 0;
                for (int j = 0; j < i; j++) {
                    sum+=j;
                }
                //System.out.println("sum==>>" + sum);
            }
            log.debug("end {}",myData.getCount());
        }, "t1").start();

        //暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }

        new Thread(() -> {
            log.debug("edit count :{}",count);
            count=20;
            //myData.setCount(25);
            //log.debug("edit count :{}",myData.getCount());
        }, "t2").start();
    }

    @Data
    static class MyData{
        private int count;

    }
}
